class Solution:
    """这个没写完,想想可能性太多了"""
    def removeDuplicateLetters(self, s: str) -> str:
        from collections import defaultdict
        mid_dict = defaultdict(list)
        for index, alpha in enumerate(s):
            mid_dict[alpha].append(index)
        res_list = []


class Solution:
    def removeDuplicateLetters(self, s: str) -> str:
        mid_list = ["0"]
        for index, alpha in enumerate(s):
            if alpha not in mid_list:
                while alpha < mid_list[-1] and s[index:].count(mid_list[-1]) > 0:
                    mid_list.pop(-1)
                mid_list.append(alpha)
        return "".join(mid_list[1:])


a = Solution()
print(a.removeDuplicateLetters("bcabc"))
print(a.removeDuplicateLetters("cbacdcbc"))
print(a.removeDuplicateLetters(""))
